package lagouhomework;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class TASK5 {

    public ArrayList<String> paixu(ArrayList<String> arr){
        ArrayList<Integer> shunxu=new ArrayList<>();
        int index=0;
        for(int i=0;i<arr.size();i++){
            if("大王".equals(arr.get(i))){
                index=170;
            }else if("小王".equals(arr.get(i))){
                index=160;
            }else if("2".equals(arr.get(i).substring(0,1))){
                index=150;
            }else if("A".equals(arr.get(i).substring(0,1))){
                index=140;
            }else if("K".equals(arr.get(i).substring(0,1))){
                index=130;
            }else if("Q".equals(arr.get(i).substring(0,1))){
                index=120;
            }else if("J".equals(arr.get(i).substring(0,1))){
                index=110;
            }else if("10".equals(arr.get(i).substring(0,2))){
                index=100;
            }else {
                index=Integer.parseInt(arr.get(i).substring(0,1))*10;
            }
            if("♠".equals(arr.get(i).substring(0,1))){
                    index +=4;
            }else if("❤".equals(arr.get(i).substring(0,1))){
                index +=3;
            }else if("♣".equals(arr.get(i).substring(0,1))){
                index +=2;
            }else if("♦".equals(arr.get(i).substring(0,1))){
                index +=1;
            }

            shunxu.add(index);
        }
        for(int i=0;i<shunxu.size()-1;i++){
            for(int j=i+1;j<shunxu.size();j++){
                if(shunxu.get(j)<shunxu.get(i)){
                    Collections.swap(shunxu,j,i);
                    Collections.swap(arr,i,j);
                }
            }
        }
        return arr;
    }
public static void main(String[] args) {
        //1，先装54张牌
        ArrayList<String> poker = new ArrayList<>();
        String[] color ={"♠","❤","♣","♦"};
        String[] numbers ={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
        poker.add("大王");
        poker.add("小王");
        for (String number : numbers) {
               for (String col : color) {
                    poker.add(number+col);
                }
             }
        //2,对扑克牌进行洗牌
        Collections.shuffle(poker);

        //3,发牌
        ArrayList<String> player =new ArrayList<>();
        ArrayList<String> player1 =new ArrayList<>();
        ArrayList<String> player2 =new ArrayList<>();
        ArrayList<String> dipai =new ArrayList<>();
        for (int i = 0; i < poker.size(); i++) {
            if(i>50){
                    dipai.add(poker.get(i));
                }else if(i%3==0){
                    player.add(poker.get(i));
                }else if(i%3==1){
                    player1.add(poker.get(i));
                }else if(i%3==2){
                    player2.add(poker.get(i));
                }
             }

        //4排序


        //5看牌
    TASK5 P1=new TASK5();
        System.out.println("玩家一牌为："+P1.paixu(player));
        System.out.println("玩家二牌为："+P1.paixu(player1));
        System.out.println("玩家三牌为："+P1.paixu(player2));
    System.out.println("底牌为："+dipai);
        }
}

